<template>
  <div>
    <!-- 学生情况 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="姓名" width="150">
        <template slot-scope="scope">
          <router-link
            :to="{ path: '/studentinfo', query: { id: scope.row.id } }"
            >{{ scope.row.student_name }}</router-link
          >
        </template>
      </el-table-column>
      <el-table-column label="学号" width="200">
        <template slot-scope="scope">
          <p>{{ scope.row.student_num }}</p>
        </template>
      </el-table-column>
      <el-table-column label="专业" width="200">
        <template slot-scope="scope">
          <p>{{ scope.row.student_class }}</p>
        </template>
      </el-table-column>
      <el-table-column label="课题" width="280">
        <template slot-scope="scope">
          <p>{{ scope.row.topic_name }}</p>
        </template>
      </el-table-column>
      <el-table-column label="任务书" width="200">
        <template slot-scope="scope">
          <a href="javascript:;" @click="download(scope.row)">{{
            scope.row.title
          }}</a>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-upload
            :headers="head"
            name="file"
            :on-success="onsuccess"
            :action="Url()"
          >
            <el-button
              @click="handleEdit(scope.$index, scope.row)"
              size="small"
              type="primary"
            >
              发放任务书
            </el-button>
          </el-upload>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  created() {
    this.getstudentinfo();
  },
  data() {
    return {
      n: "",
      tableData: [],
      head: {
        authorization: window.sessionStorage.token,
      },
    };
  },
  methods: {
    download(row) {
      // console.log(row);
      location.href = "http://127.0.0.1:8080/api/download_1?id=" + row.task_id;
    },
    // 获取所带学生以及任务书信息
    getstudentinfo() {
      this.$http
        .get("http://127.0.0.1:8080/teacher/getstudentTask")
        .then((res) => {
          // console.log(res);
          if (res.data.status == 0) {
            this.tableData = res.data.data;
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    Url() {
      return "http://127.0.0.1:8080/teacher/add?student_num=" + this.n;
    },
    handleEdit(index, row) {
      // console.log(row);
      this.n = row.student_num;
    },
    onsuccess() {
      this.getstudentinfo();
    },
  },
};
</script>
<style lang="less" scoped>
</style>
